#include <iostream>
#include <unistd.h>
#include <signal.h>
using namespace std;

volatile int flag = 0;

void changeFlag(int signum)
{
    cout << "进程捕捉到了一个信号： " << signum << " Pid: " << getpid() << endl;

    cout << "change flag: " << flag;
    flag = 1;
    cout << "->" << flag << endl;
}

int main()
{
    signal(2, changeFlag);
    while (!flag)
        ;
    cout << "进程正常退出后：" << flag << endl;
}